# Example input file to test 1/8 of a coupon with a neo-hookean
# material (based on neohookean_example.i)

# Status: not working (migrating to automatic differentiation)

[GlobalParams]
  displacements = 'disp_x disp_y disp_z'
  order = first
[]

[Mesh]
  # Remember to uncomment the Physical Surface lines in
  # dbWide.geo to get the boundaries
  file = dbWide.msh
  dim = 3
[]

[Modules/TensorMechanics/Master]
  [./all]
    # Finite strain is useful for hyperelasticity
    strain = FINITE
    # Detects the change of the mesh to second order and
    # automatically sets the variables
    add_variables = true
    # Automatically creates the auxvariables and auxkernels
    # needed to output these stress quanities
    generate_output = 'strain_yx strain_yy strain_yz strain_zx strain_zy strain_zz stress_yx stress_yy stress_yz stress_zx stress_zy stress_zz vonmises_stress'
  [../]
[]

[Materials]
  [./elasticity_tensor]
    type = ComputeElasticityTensorNeohookean
    E = 30e6
    nu = 0.4
  [../]

  [./stress]
    type = ComputeStressNeohookean
    E = 30e6
    nu = 0.4
  [../]
[]

[BCs]
  [./fix_x]
    type = PresetBC
    variable = disp_x
    boundary = left
    value = 0
  [../]
  [./fix_y]
    type = PresetBC
    variable = disp_y
    boundary = back
    value = 0
  [../]
  [./fix_z]
    type = PresetBC
    variable = disp_z
    boundary = bottom
    value = 0.0
  [../]
  [./pull]
    # * Make displacement proportional to time
    # ** The geometry has an initial length of
    #    9.015359609265856e-3; a final stretch of 1.5 is
    #    sought:
    #    \( \max(\Delta{l}) = l_{0} * (\lambda - 1) \)
    #    dl = l0 * (lambda - 1)
    #    dl = 9.015359609265856e-3 * 0.5
    #       = 0.004507679804635
    # Not working
    # function = '0.004507679804635 * t' # final t = 1
    # function = '500e-6 * t' # final t = 1
    #
    # The side length is 1e-3, this is 0.5e-3
    function = '0.004507679804635 * t' # final t = 1
    type = FunctionPresetBC
    variable = disp_z
    boundary = top
  [../]
[]

[Preconditioning]
  # "To test (computeQpJacobian and
  # computeQpOffDiagJacobian) add the following block to
  # your input"--http://mooseframework.org/moose/help/development/analyze_jacobian.html
  # SingleMatrixPreconditioner
  [./SMP]
    type = SMP
    full = true
  [../]
[]

[Executioner]
  type = Transient
  end_time = 1
  num_steps = 200

  solve_type = 'NEWTON'

  petsc_options = '-snes_ksp_ew'
  petsc_options_iname = '-pc_type -sub_pc_type -pc_asm_overlap -ksp_gmres_restart'
  petsc_options_value = 'asm lu 1 101'
[]
# [Executioner]
#   type = Steady
#
#   solve_type = 'NEWTON'
#   # # To check the Jacobian (together with solve_type = "NEWTON"):
#   # # (from the mailing list: -ksp_view_mat)
#   # petsc_options = '-snes_ksp_ew -ksp_view_mat'
#   petsc_options = '-snes_ksp_ew'
#   petsc_options_iname = '-pc_type -sub_pc_type -pc_asm_overlap -ksp_gmres_restart'
#   petsc_options_value = 'asm lu 1 101'
# []

[Postprocessors]
  # See other postprocessors here:
  # [moose/framework/src/postprocessors/]
  [./ave_stress_bottom_z]
    type = SideAverageValue
    variable = stress_zz
    boundary = bottom
  [../]
  [./ave_strain_bottom_z]
    type = SideAverageValue
    variable = strain_zz
    boundary = bottom
  [../]
  [./stress_el0_zz]   # This could also be stress_zz
    # This post-processor does sum over element and divides
    # by volume. When using this post-processor, it is
    # better to set allow_renumbering = false in the [Mesh]
    # block
    type = ElementalVariableValue
    variable = stress_zz
    elementid = 0
  [../]
  [./stress_el_yy]
    # This post-processor does integration over the element,
    # and normalises by volume (and does not need elementid)
    type = ElementAverageValue
    variable = stress_yy
  [../]
  [./disp_top_z]
    type = SideAverageValue
    variable = disp_z
    boundary = top
    execute_on = 'initial timestep_end'
  [../]
  [./coupon_stretch]
    # Use a MOOSE function to calculate the coupon of the
    # stretch
    type = FunctionValuePostprocessor
    # This function must exist in the [Functions] block
    function = overal_stretch_z
    execute_on = 'initial timestep_end'
  [../]
  [./ave_vonmises_stress_bottom]
    type = SideAverageValue
    variable = vonmises_stress
    boundary = bottom
  [../]
[]

[Functions]
  # Create a function to calculate the instantaneous stretch
  # as measured from the top to the bottom of the coupon
  # (remember that this is 1/8 of a coupon)
  [./overal_stretch_z]
    type = ParsedFunction
    # The variables and its values are given in something
    # similar to a table (we take disp_top_z from the
    # [Postprocessors] block; the extra space is for
    # readability):
    vars = "l0                   displ"
    vals = "9.015359609265856e-3 disp_top_z"
    # This is the value that the ParsedFunction gets (both
    # variables are defined within this block)
    # \(Stretch = \Delta{l} / l_{0}\)
    value = "(displ) / l0 + 1"
  [../]
[]

[Outputs]
  # * Get an Exodus file
  # exodus = true
  # ** This replaces default Exodus file
  [./o]
    type = Exodus
    # *** May be I can get values at the nodes with ParaView
    #     in this way?
    elemental_as_nodal = true
    # Discontinuous output implies that elemental values are
    # output as nodal values--Exodus.C
    discontinuous = true
  [../]
  # * The simulation is taking long. I want to know what is
  #   going on (print log and screen output)
  print_perf_log = false
  console = true
  # Export CSV (comma-separated data as text file)
  csv = true
  # Test
  perf_log = true
[]
